home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 25 / Cream of the Crop 25.iso / program / flip3206.zip / FLIP32_A.ASM < prev    next >
Assembly Source File  |  1997-03-23  |  9KB  |  214 lines

  1. ;----------------------------------------------------------------------------
  2. ; FLIP32_A.ASM           copyright (c) 1996-97, Xavier Defrang (aka brioche)
  3. ;----------------------------------------------------------------------------
  4. ; 32-bit protected mode FLI player
  5. ;----------------------------------------------------------------------------
  6. ; here are some great routines that does some great stuff... enjoy! :)
  7. ;----------------------------------------------------------------------------
  8. ; e-mail: 106146.1452@compuserve.com
  9. ;----------------------------------------------------------------------------
  10.  
  11. FLI_COLOR_ID    equ     000bh                   ; some chunk magic numbers
  12. FLI_LC_ID       equ     000ch
  13. FLI_BLACK_ID    equ     000dh
  14. FLI_BRUN_ID     equ     000fh
  15. FLI_COPY_ID     equ     0010h
  16. SCREEN_WIDTH    equ     320                     ; FLI's are always 320x200
  17. SCREEN_HEIGHT   equ     200
  18. SCREEN_SIZE     equ     SCREEN_WIDTH*SCREEN_HEIGHT
  19. PWA             equ     03c8h                   ; Pixel Write Address
  20. ISR1            equ     03dAh                   ; Input Status Register 1
  21. VIDEO_MEM       equ     0a0000h                 ; video memory physical addr
  22.  
  23.         .386p
  24.         .model  flat
  25.  
  26. ;----------------------------------------------------------------------------
  27.             
  28. data            segment public use32            ; don't need any data but...
  29.             
  30. data            ends    
  31.             
  32. ;----------------------------------------------------------------------------
  33.             
  34. code            segment public use32
  35.             
  36.         assume  cs:code, ds:data
  37.             
  38. public          vmode                           ; setup bios video mode
  39. public          flip32_wait                     ; wait x jiffies (vbl sync.)
  40. public          flip32_unpack                   ; unpack a frame into a buf
  41.             
  42. ;----------------------------------------------------------------------------
  43.                 
  44. vmode           proc    near                    ; hum... does it really need
  45.                         ; to be commented? :)
  46.         int     10h                ; eax = vid_mode_number
  47.         ret            
  48.                    
  49. vmode           endp           
  50.                    
  51. ;----------------------------------------------------------------------------
  52.                    
  53. flip32_wait     proc    near                    ; using timer is better...
  54.                         ; ...but time is money! :)
  55.         or      ecx, ecx                
  56.         jz      go_ahead                ; if ( ecx == 0 ) exit
  57.         mov     dx, ISR1
  58. in_display:     in      al, dx                  ; wait for vbl (≈1/70s)
  59.         test    al, 00001000b
  60.         jnz     in_display
  61. in_retrace:     in      al, dx
  62.         test    al, 00001000b
  63.         jz      in_retrace
  64.         dec     ecx                      
  65.         jnz     in_display              ; loop...
  66. go_ahead:       ret           
  67.  
  68. flip32_wait     endp        
  69.              
  70. ;----------------------------------------------------------------------------
  71.               
  72. flip32_unpack   proc    near
  73.                   
  74.         push    ebp
  75.         mov     ebp, esp                
  76.         
  77.         arg     src : dword, dst : dword, chunks : dword
  78.  
  79.         ;-- i'm sure i could optimize the way o send the params
  80.         ;-- to this proc... pfff... so lazy! :)
  81.  
  82.         mov     esi, src                ; [esi] = packed frame data
  83.  
  84. nextchunk:      cmp     chunks, 0               ; is it done for this frame?
  85.         je      exit
  86.         dec     chunks                   
  87.         mov     ax, word ptr [esi+4]    ; get frame magic number...
  88.         add     esi, 6          
  89.         cmp     ax, FLI_COLOR_ID        ; and jump to the right place!
  90.         je      fli_color      
  91.         cmp     ax, FLI_LC_ID  
  92.         je      fli_lc         
  93.         cmp     ax, FLI_BLACK_ID
  94.         je      fli_black      
  95.         cmp     ax, FLI_BRUN_ID
  96.         je      fli_brun       
  97.         cmp     ax, FLI_COPY_ID
  98.         je      fli_copy       
  99.         jmp     nextchunk               ; burp... next one please!
  100.  
  101. ;-- process fli_color chunk -------------------------------------------
  102.                        
  103. fli_color:      mov     bx, word ptr [esi]      ; get packets in chunk
  104.         add     esi, 2
  105.         xor     ax, ax                  ; start at color index 0
  106.         xor     ecx, ecx         
  107. color_packloop: or      bx, bx                  ; finish with packets?
  108.         jz      nextchunk      
  109.         dec     bx                      
  110.         add     al, byte ptr [esi]      ; get color to start from
  111.         mov     dx, PWA        
  112.         out     dx, al                  ; send it to the DAC
  113.         inc     dl                      ; dx = Pixel Color Value reg
  114.         mov     cl, byte ptr [esi+1]    ; get # of colors that change
  115.         or      cl, cl                  ; null? 
  116.         jnz     color_skip     
  117.         inc     ch                      ; 0 means 256
  118. color_skip:     add     al, cl                  ; set color to restart from
  119.         lea     ecx, [ecx+ecx*2]        ; multiply by 3 (tricky! uh?)
  120.         add     esi, 2          
  121.         rep     outsb                   ; set palette
  122.         jmp     color_packloop          ; process next color packet
  123.  
  124. ;-- process fli_lc chunk -------------------------------------------
  125.                        
  126. fli_lc:         movzx   edi, word ptr [esi]     ; get start row
  127.         lea     edi, [edi+edi*4]        ; edi *= 5
  128.         shl     edi, 6                  ; edi *= 64 (note: 5*64=320!)
  129.         add     edi, dst                ; edi += dest_address
  130.         mov     bx, word ptr [esi+2]    ; get # lines that change
  131.         add     esi, 4          
  132.         xor     ecx, ecx                ; clear counter
  133. lc_lineloop:    or      bx, bx         
  134.         jz      nextchunk               ; check line counter...
  135.         dec     bx             
  136.         push    edi                     ; save start row offset
  137.         mov     dl, byte ptr [esi]      ; get # of packets in line
  138.         inc     esi             
  139. lc_packloop:    or      dl, dl         
  140.         jz      lc_nextline             ; check packet counter
  141.         dec     dl             
  142.         mov     cl, byte ptr [esi]      ; bytes to skip
  143.         add     edi, ecx         
  144.         mov     cl, byte ptr [esi+1]    ; bytes that we gonna update
  145.         or      cl, cl         
  146.         jns     lc_copy                 ; if positive then copy...
  147.         neg     cl             
  148.         mov     al, byte ptr [esi+2]
  149.         add     esi, 3          
  150.         rep     stosb                   ; fill with the same byte
  151.         jmp     lc_packloop    
  152. lc_copy:        add     esi, 2          
  153.         rep     movsb                   ; copy bytes from src to dst
  154.         jmp     lc_packloop    
  155. lc_nextline:    pop     edi                     ; restore start row offset...
  156.         add     edi, SCREEN_WIDTH       ; ...and jump to next line!
  157.         jmp     lc_lineloop    
  158.  
  159. ;-- process fli_black chunk (a pretty hard one! :)) ---------------
  160.                        
  161. fli_black:      mov     edi, dst                ; load target address
  162.         mov     ecx, SCREEN_SIZE/4      ; set up counter
  163.         xor     eax, eax                ; we gonna fill with null
  164.         rep     stosd                   ; fill it!
  165.         jmp     nextchunk      
  166.  
  167. ;-- process fli_brun chunk -----------------------------------
  168.                        
  169. fli_brun:       mov     edi, dst                ; we begin from dst...
  170.         mov     bx, SCREEN_HEIGHT       ; we update the whole screen
  171.         xor     cx, cx           
  172. brun_lineloop:  push    edi                     ; save start row address
  173.         mov     dl, byte ptr [esi]      ; packet in line
  174.         inc     esi             
  175. brun_packloop:  or      dl, dl         
  176.         jz      brun_nextline           ; check packet counter
  177.         dec     dl             
  178.         mov     cl, byte ptr [esi]      ; bytes to write
  179.         or      cl, cl         
  180.         js      brun_copy               ; if negative then copy
  181.         mov     al, byte ptr [esi+1]
  182.         add     esi, 2          
  183.         rep     stosb                   ; fill with the same byte
  184.         jmp     brun_packloop  
  185. brun_copy:      neg     cl             
  186.         inc     esi             
  187.         rep     movsb                   ; copy from src to dst...
  188.         jmp     brun_packloop  
  189. brun_nextline:  pop     edi                     ; get back start row offset
  190.         add     edi, SCREEN_WIDTH       ; we go to the next line
  191.         dec     bx
  192.         jnz     brun_lineloop           ; we will process next line
  193.         jmp     nextchunk      
  194.  
  195. ;-- process fli_copy chunk -------------------------------------------
  196.                        
  197. fli_copy:       mov     edi, dst                ; pfff... a difficult one!
  198.         mov     ecx, SCREEN_SIZE/4
  199.         rep     movsd                   ; copy 320*200 screen
  200.         jmp     nextchunk      
  201.                        
  202. exit:           mov     esp, ebp                
  203.         pop     ebp
  204.  
  205.         ret                             
  206.                        
  207. flip32_unpack   endp                   
  208.                        
  209. ;----------------------------------------------------------------------------
  210.                        
  211. code            ends
  212.  
  213.         end
  214.